home *** CD-ROM | disk | FTP | other *** search
/ BUG 1 / BUGCD1996_0708.ISO / pc / util / minilin / minilin.exe / SBIN / NETCONFI.{1P < prev    next >
Text File  |  1994-06-09  |  15KB  |  511 lines

  1. #!/bin/sh
  2. # This checks IP address syntax.
  3. # usage: syntax_check ADDRESS #-OF-EXPECTED-SEGMENTS (up to 4)
  4. # example: syntax_check 123.22.43.1 4
  5. # returns: 0=found correct  1=too many fields  2=non numeric field found
  6. syntax_check_color() {
  7.   RET_CODE=0 
  8.   SCRATCH=$1
  9.   SCRATCH=`echo $SCRATCH | tr "." "/"`
  10.   INDEX=$2
  11.   while [ ! "$INDEX" = "0" ]; do
  12.     # OK, so I'm a LISP-head :^)
  13.     FIELD=`basename $SCRATCH`
  14.     SCRATCH=`dirname $SCRATCH`
  15.     if expr $FIELD + 1 1> /dev/null 2> /dev/null; then
  16.       GOOD=y
  17.     else
  18.       RET_CODE=2; # non-numeric field
  19.     fi
  20.     INDEX=`expr $INDEX - 1`
  21.   done
  22.   if [ ! "$SCRATCH" = "." ]; then
  23.     RET_CODE=1; # too many arguments
  24.   fi
  25.   if [ "$3" = "WARN" -a ! "$RET_CODE" = "0" ]; then
  26.     cat << EOF > /tmp/tmpmsg
  27.  
  28. The address you have entered seems to be non-standard. We were expecting
  29. $2 groups of numbers seperated by dots, like: 127.0.0.1
  30. Are you absolutely sure you want to use the address $1?
  31.  
  32. EOF
  33.     dialog --title "WARNING" --yesno "`cat /tmp/tmpmsg`" 9 72
  34.     if [ $? = 0 ]; then
  35.       RET_CODE = 0;
  36.     fi
  37.     rm -r /tmp/tmpmsg
  38.   else
  39.     if [ "$3" = "ECHO" ]; then
  40.       echo $RET_CODE;
  41.     fi
  42.   fi
  43.   return $RET_CODE;
  44. }
  45.  
  46. if [ ! -r vmlinuz -a ! -r zImage ]; then # cheap, but it works :^)
  47.  cd /
  48. fi;
  49.  
  50. # IMPORTANT!!! NO LEADING '/' in the paths below, or this script will not
  51. # function from the bootdisk.
  52. IFCONFIG=sbin/ifconfig            # Where ifconfig program is.
  53. ROUTE=sbin/route            # Where route program is.
  54. RC=etc/rc.d/rc.inet1            # Where rc.inet1 file is.
  55. RESOLV=etc/resolv.conf            # Where resolv.conf file is.
  56. HOSTS=etc/hosts                 # Where hosts file is.
  57. ETCNETWORKS=etc/networks        # Where networks file is.
  58. SMAIL=var/lib/smail/config        # Smail configuration file
  59. ELMRC=var/lib/elm/elm.rc        # ELM rc file
  60. #
  61. # defaults:
  62. NETWORK=127.0.0.0
  63. IPADDR=127.0.0.1
  64. #
  65. ############################################################################
  66. #             Question and answer.
  67. ############################################################################
  68. #
  69. cat << EOF > /tmp/tmpmsg
  70.  
  71. Now we will attempt to configure your mail and TCP/IP. This 
  72. process probably won't work on all possible network 
  73. configurations, but should give you a good start. You will be
  74. able to reconfigure your system at any time by typing:
  75.   
  76.   netconfig
  77.  
  78. EOF
  79. dialog --title "NETWORK CONFIGURATION" --msgbox "`cat /tmp/tmpmsg`" 12 70
  80. HOSTNAME=""
  81. while [ "$HOSTNAME" = "" ]; do
  82. cat << EOF > /tmp/tmpmsg
  83. First, we'll need the name you'd like to give your host. Only
  84. the base hostname is needed right now. (not the domain)
  85.  
  86. Enter hostname:
  87. EOF
  88.  dialog --title "ENTER HOSTNAME" --inputbox "`cat /tmp/tmpmsg`" 11 70 \
  89.  2> /tmp/SeThost
  90.  if [ $? = 1 -o $? = 255 ]; then
  91.   rm -f /tmp/SeThost /tmp/tmpmsg
  92.   exit
  93.  fi
  94.  HOSTNAME="`cat /tmp/SeThost`"
  95.  rm -f /tmp/SeThost /tmp/tmpmsg
  96. done
  97.  
  98. while [ "$DOMAIN" = "" ]; do
  99. cat << EOF > /tmp/tmpmsg
  100. Now, we need the domain name. Do not supply a leading '.'
  101.  
  102. Enter domain name for $HOSTNAME: 
  103. EOF
  104.  dialog --title "ENTER DOMAINNAME" --inputbox "`cat /tmp/tmpmsg`" \
  105. 10 70 2> /tmp/SeTdom
  106.  if [ $? = 1 -o $? = 255 ]; then
  107.   rm -f /tmp/SeTdom /tmp/tmpmsg
  108.   exit
  109.  fi
  110.  DOMAIN="`cat /tmp/SeTdom`"
  111.  rm -f /tmp/SeTdom /tmp/tmpmsg
  112. done
  113. echo $HOSTNAME.$DOMAIN > etc/HOSTNAME
  114.  
  115. cat << EOF > /tmp/tmpmsg
  116. If you only plan to use TCP/IP through loopback, then your
  117. IP address will be 127.0.0.1 and we can skip a lot of the 
  118. following questions.
  119.  
  120. Do you plan to ONLY use loopback? 
  121. EOF
  122. dialog --title "LOOPBACK ONLY?" --yesno "`cat /tmp/tmpmsg`" 9 70
  123. if [ $? = 0 ]; then
  124.  LOOPBACK="y"
  125. else
  126.  LOOPBACK="n"
  127. fi
  128.  
  129. if [ -r etc/rc.d/rc.inet1 -a "$LOOPBACK" = "n" ]; then
  130.  
  131.  while [ 0 ]; do
  132.   cat << EOF > /tmp/tmpmsg
  133. Enter your IP address for the local machine. Example: 
  134. 111.112.113.114
  135. Enter IP address for $HOSTNAME (aaa.bbb.ccc.ddd): 
  136. EOF
  137.   dialog --title "ENTER LOCAL IP ADDRESS" --inputbox "`cat /tmp/tmpmsg`" \
  138. 10 68 2> /tmp/SeTlip
  139.   if [ $? = 1 -o $? = 255 ]; then
  140.    rm -f /tmp/SeTlip /tmp/tmpmsg
  141.    exit
  142.   fi
  143.   IPADDR="`cat /tmp/SeTlip`"
  144.   rm -f /tmp/SeTlip /tmp/tmpmsg
  145.   if [ "$IPADDR" = "" ]; then
  146.     continue;
  147.   fi
  148.   syntax_check_color $IPADDR 4 WARN
  149.   if [ $? = 0 ]; then
  150.     break;
  151.   fi
  152.  done
  153.  
  154.  while [ 0 ]; do
  155.   cat << EOF > /tmp/tmpmsg
  156. Enter your network address. This will usually be your
  157. IP address with the last number replaced by 0, such as
  158. 111.112.113.0
  159. Enter network address (aaa.bbb.ccc.ddd):
  160. EOF
  161.   dialog --title "ENTER NETWORK ADDRESS" --inputbox \
  162. "`cat /tmp/tmpmsg`" 11 65 2> /tmp/SeTneta
  163.   if [ $? = 1 -o $? = 255 ]; then
  164.    rm -f /tmp/SeTneta /tmp/tmpmsg
  165.    exit
  166.   fi
  167.   NETWORK="`cat /tmp/SeTneta`"
  168.   rm -f /tmp/SeTneta /tmp/tmpmsg
  169.   if [ "$NETWORK" = "" ]; then
  170.     continue;
  171.   fi
  172.   syntax_check_color $NETWORK 4 WARN
  173.   if [ $? = 0 ]; then
  174.     break;
  175.   fi
  176.  done
  177.  
  178.  while [ 0 ]; do
  179.   cat << EOF > /tmp/tmpmsg
  180. Enter your gateway address, such as 111.112.113.1
  181. Enter gateway address (aaa.bbb.ccc.ddd):
  182. EOF
  183.   dialog --title "ENTER GATEWAY ADDRESS" --inputbox "`cat /tmp/tmpmsg`" \
  184. 9 65 2> /tmp/SeTgate
  185.   if [ $? = 1 -o $? = 255 ]; then
  186.    rm -f /tmp/SeTgate /tmp/tmpmsg
  187.    exit
  188.   fi
  189.   GATEWAY="`cat /tmp/SeTgate`"
  190.   rm -f /tmp/SeTgate /tmp/tmpmsg
  191.   if [ "$GATEWAY" = "" ]; then
  192.     continue;
  193.   fi
  194.   syntax_check_color $GATEWAY 4 WARN
  195.   if [ $? = 0 ]; then
  196.     break;
  197.   fi
  198.  done
  199.  
  200.  while [ 0 ]; do
  201.   cat << EOF > /tmp/tmpmsg
  202. Enter your netmask. This will generally look something
  203. like this: 255.255.255.0
  204. Enter netmask (aaa.bbb.ccc.ddd):
  205. EOF
  206.   dialog --title "ENTER NETMASK" --inputbox "`cat /tmp/tmpmsg`" \
  207. 10 65 2> /tmp/SeTnmask
  208.   if [ $? = 1 -o $? = 255 ]; then
  209.    rm -f /tmp/SeTnmask /tmp/tmpmsg
  210.    exit
  211.   fi
  212.   NETMASK="`cat /tmp/SeTnmask`"
  213.   rm -f /tmp/SeTnmask /tmp/tmpmsg
  214.   if [ "$NETMASK" = "" ]; then
  215.     continue;
  216.   fi
  217.   syntax_check_color $NETMASK 4 WARN
  218.   if [ $? = 0 ]; then
  219.     break;
  220.   fi
  221.  done
  222.  
  223.  while [ "$BROADCAST" = "" ]; do
  224.   cat << EOF > /tmp/tmpmsg
  225. Your broadcast address will usually be your IP address
  226. with 255 replacing the last value, such as: 111.112.113.255
  227. Enter broadcast address (aaa.bbb.ccc.ddd): 
  228. EOF
  229.   dialog --title "ENTER BROADCAST ADDRESS" --inputbox \
  230. "`cat /tmp/tmpmsg`" 10 70 2> /tmp/SeTbcast
  231.   if [ $? = 1 -o $? = 255 ]; then
  232.    rm -f /tmp/tmpmsg /tmp/SeTbcast
  233.   fi
  234.   BROADCAST="`cat /tmp/SeTbcast`"
  235.   rm -f /tmp/tmpmsg /tmp/SeTbcast
  236.   if [ "$BROADCAST" = "" ]; then
  237.     continue;
  238.   fi
  239.   syntax_check_color $BROADCAST 4 WARN
  240.   if [ $? = 0 ]; then
  241.     break;
  242.   fi
  243.  done
  244.  
  245. else
  246.  if [ ! -r etc/rc.d/rc.inet1 ]; then
  247.   cat << EOF > /tmp/tmpmsg
  248.  
  249. You do not seem to have TCP/IP installed, so all I can really set
  250. up for you is your hostname/domainname. This won't mean much 
  251. since you're not on the network, but it will let you have the 
  252. hostname you prefer shown at the login prompt.
  253.  
  254. EOF
  255.   dialog --title "SKIPPING MOST OF THE CONFIG PROCESS" \
  256. --infobox "`cat /tmp/tmpmsg`" 10 70
  257.  fi
  258. fi
  259.  
  260. #
  261. ############################################################################
  262. #              The rc.inet1 file.
  263. ############################################################################
  264. #
  265. if [ -f $RC ]; then 
  266.  cp $RC tmp/`basename $RC`.OLD
  267. # echo "Creating /$RC..."
  268. if [ "$LOOPBACK" = "n" ]; then # we are using an ethernet card
  269.  /bin/cat <<EOF >$RC
  270. #! /bin/sh
  271. #
  272. # rc.inet1    This shell script boots up the base INET system.
  273. #
  274. # Version:    @(#)/etc/rc.d/rc.inet1    1.01    05/27/93
  275. #
  276.  
  277. HOSTNAME=\`cat /etc/HOSTNAME\`
  278.  
  279. # Attach the loopback device.
  280. /$IFCONFIG lo 127.0.0.1
  281. /$ROUTE add -net 127.0.0.0
  282.  
  283. # IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the 
  284. # eth0 interface. If you're only using loopback or SLIP, don't include the
  285. # rest of the lines in this file.
  286.  
  287. # Edit for your setup.
  288. IPADDR="$IPADDR"    # REPLACE with YOUR IP address!
  289. NETMASK="$NETMASK"    # REPLACE with YOUR netmask!
  290. NETWORK="$NETWORK"    # REPLACE with YOUR network address!
  291. BROADCAST="$BROADCAST"    # REPLACE with YOUR broadcast address, if you
  292.             # have one. If not, leave blank and edit below.
  293. GATEWAY="$GATEWAY"    # REPLACE with YOUR gateway address!
  294.  
  295. # Uncomment ONLY ONE of the three lines below. If one doesn't work, try again.
  296. # /$IFCONFIG eth0 \${IPADDR} netmask \${NETMASK} broadcast \${BROADCAST}
  297. /$IFCONFIG eth0 \${IPADDR} broadcast \${BROADCAST} netmask \${NETMASK}
  298. # /$IFCONFIG  eth0 \${IPADDR} netmask \${NETMASK} 
  299.  
  300. # Uncomment these to set up your IP routing table.
  301. /$ROUTE add -net \${NETWORK} netmask \${NETMASK}
  302. /$ROUTE add default gw \${GATEWAY} metric 1
  303.  
  304. # End of rc.inet1
  305. EOF
  306.   chmod 755 $RC
  307.  else # we are only using loopback
  308.   /bin/cat <<EOF >$RC
  309. #! /bin/sh
  310. #
  311. # rc.inet1    This shell script boots up the base INET system.
  312. #
  313. # Version:    @(#)/etc/rc.d/rc.inet1    1.01    05/27/93
  314. #
  315.  
  316. HOSTNAME=\`cat /etc/HOSTNAME\`
  317.  
  318. # Attach the loopback device.
  319. /$IFCONFIG lo 127.0.0.1
  320. /$ROUTE add -net 127.0.0.0
  321.  
  322. # IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the 
  323. # eth0 interface. If you're only using loopback or SLIP, don't include the
  324. # rest of the lines in this file.
  325.  
  326. # Edit for your setup.
  327. #IPADDR="$IPADDR"    # REPLACE with YOUR IP address!
  328. #NETMASK="$NETMASK"    # REPLACE with YOUR netmask!
  329. #NETWORK="$NETWORK"    # REPLACE with YOUR network address!
  330. #BROADCAST="$BROADCAST"    # REPLACE with YOUR broadcast address, if you
  331.             # have one. If not, leave blank and edit below.
  332. #GATEWAY="$GATEWAY"    # REPLACE with YOUR gateway address!
  333.  
  334. # Uncomment ONLY ONE of the three lines below. If one doesn't work, try again.
  335. # /$IFCONFIG eth0 \${IPADDR} netmask \${NETMASK} broadcast \${BROADCAST}
  336. #/$IFCONFIG eth0 \${IPADDR} broadcast \${BROADCAST} netmask \${NETMASK}
  337. # /$IFCONFIG  eth0 \${IPADDR} netmask \${NETMASK} 
  338.  
  339. # Uncomment these to set up your IP routing table.
  340. #/$ROUTE add -net \${NETWORK} netmask \${NETMASK}
  341. #/$ROUTE add default gw \${GATEWAY} metric 1
  342.  
  343. # End of rc.inet1
  344. EOF
  345.   chmod 755 $RC
  346.  fi # write out the script
  347. fi # only alter if it already exists
  348. #
  349. ############################################################################
  350. #              The networks file.
  351. ############################################################################
  352. #
  353. if [ -f $ETCNETWORKS ]; then
  354.  cp $ETCNETWORKS tmp/`basename $ETCNETWORKS`.OLD
  355. fi
  356. #echo "Creating /$ETCNETWORKS..."
  357. /bin/cat <<EOF >$ETCNETWORKS
  358. #
  359. # networks    This file describes a number of netname-to-address
  360. #        mappings for the TCP/IP subsystem.  It is mostly
  361. #        used at boot time, when no name servers are running.
  362. #
  363. # Version:    @(#)/etc/networks    2.00    04/30/93
  364. #
  365. # Author:    Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org
  366. #
  367.  
  368. loopback    127.0.0.0
  369. localnet    $NETWORK
  370.  
  371. # End of networks.
  372. EOF
  373. chmod 644 $ETCNETWORKS
  374. #
  375. ############################################################################
  376. #               The hosts file.
  377. ############################################################################
  378. #
  379. #echo "Creating /$HOSTS..."
  380. if [ -f $HOSTS ];then cp $HOSTS tmp/`basename $HOSTS`.OLD;fi
  381. /bin/cat <<EOF >$HOSTS
  382. #
  383. # hosts        This file describes a number of hostname-to-address
  384. #        mappings for the TCP/IP subsystem.  It is mostly
  385. #        used at boot time, when no name servers are running.
  386. #        On small systems, this file can be used instead of a
  387. #        "named" name server.  Just add the names, addresses
  388. #        and any aliases to this file...
  389. #
  390. # Version:    @(#)/etc/hosts        2.00    04/30/93
  391. #
  392. # Author:    Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  393. #
  394.  
  395. # For loopbacking.
  396. 127.0.0.1    localhost
  397. $IPADDR         $HOSTNAME.$DOMAIN $HOSTNAME
  398.  
  399. # End of hosts.
  400. EOF
  401. chmod 644 $HOSTS
  402. #
  403. ##########################################################################
  404. # The Smail 3.1.28 configuration file 
  405. ##########################################################################
  406. #
  407. mkdir -p `dirname $SMAIL`
  408. if [ -f $SMAIL ];then 
  409.  cp $SMAIL tmp/`basename $SMAIL`.OLD
  410. fi
  411. #echo "Creating /$SMAIL..."
  412. /bin/cat <<EOF >$SMAIL
  413. #
  414. #    smail configuration for $HOSTNAME
  415. # (see smail(5) man page for details and other options)
  416. #
  417. -smtp_debug
  418. hostname=$HOSTNAME.$DOMAIN
  419. visible_domain=$DOMAIN
  420. more_hostnames=$HOSTNAME.$DOMAIN
  421. postmaster=postmaster
  422. smtp_accept_max=10
  423. EOF
  424. echo 'smtp_banner="$primary_name Linux Smail$version #$compile_num ready at $date"' >> $SMAIL
  425. echo 'received_field="Received: \ ' >> $SMAIL
  426. echo '    ${if def:sender_host \ ' >> $SMAIL
  427. echo '        {from $sender_host by $primary_name \ ' >> $SMAIL
  428. echo '        ${if def:sender_proto: with $sender_proto}\ ' >> $SMAIL
  429. echo '        \n\t(Linux Smail$version #$compile_num) }\ ' >> $SMAIL
  430. echo '    else{by $primary_name ${if def:sender_proto:with $sender_proto }\ ' >> $SMAIL
  431. echo '        (Linux Smail$version #$compile_num)\n\t}}\ ' >> $SMAIL
  432. echo '    id $message_id; $spool_date" ' >> $SMAIL
  433. chmod 644 $SMAIL
  434. #
  435. ############################################################################
  436. # The ELM rc file
  437. ############################################################################
  438. #
  439. mkdir -p `dirname $ELMRC`
  440. if [ -f $ELMRC ];then
  441.  cp $ELMRC tmp/`basename $ELMRC`.OLD
  442. fi
  443. #echo "Creating /$ELMRC..."
  444. /bin/cat <<EOF >$ELMRC
  445. #------------------------ global elm.rc file ------------------
  446. #
  447. # this expects any global aliases in /usr/lib/aliases.text
  448. #
  449. # you probably also want to set the visible_name parameter in 
  450. # /usr/lib/smail/config if you use smail3.1.28
  451. #
  452. # this is the unqualified hostname
  453. #
  454. hostname = $HOSTNAME
  455. #
  456. # this is the local domain
  457. #
  458. hostdomain = .$DOMAIN
  459. #
  460. # this is the fully qualified hostname
  461. #
  462. hostfullname = $HOSTNAME.$DOMAIN
  463. EOF
  464. chmod 644 $ELMRC
  465. #
  466. ############################################################################
  467. #            The resolv.conf file.
  468. ############################################################################
  469. #
  470. if [ "$LOOPBACK" = "n" ]; then
  471.  while [ "$NAMESERVER" = "" ]; do
  472.   cat << EOF > /tmp/tmpmsg
  473. Here is your current IP address, full hostname, and base hostname:
  474. $IPADDR       $HOSTNAME.$DOMAIN    $HOSTNAME
  475.  
  476. Please give the IP address of the name server to use. 
  477. You can add more Domain Name Servers by editing /$RESOLV.
  478.  
  479. Name Server for domain $DOMAIN (aaa.bbb.ccc.ddd): 
  480. EOF
  481.   dialog --title "SELECT NAMESERVER" --inputbox \
  482. "`cat /tmp/tmpmsg`" 14 72 2> /tmp/SeTns
  483.   if [ $? = 1 -o $? = 255 ]; then
  484.    rm -f /tmp/tmpmsg /tmp/SeTns 
  485.   fi
  486.   NAMESERVER="`cat /tmp/SeTns`"
  487.   rm -f /tmp/tmpmsg /tmp/SeTns 
  488.  done
  489.  
  490.  if [ -f $RESOLV ]; then cp $RESOLV tmp/`basename $RESOLV`.OLD;fi
  491.  echo "domain $DOMAIN" >$RESOLV
  492.  echo "nameserver $NAMESERVER" >>$RESOLV
  493. else
  494.  echo "domain $DOMAIN" >$RESOLV
  495. fi
  496. if [ "$LOOPBACK" = "n" ]; then chmod 644 $RESOLV ;fi
  497. #
  498. ############################################################################
  499. #             Change permissions and exit.
  500. ############################################################################
  501. #
  502.  
  503. cat << EOF > /tmp/tmpmsg
  504.  
  505. Your networking software has now been configured. 
  506.  
  507. EOF
  508. dialog --title "NETWORK SETUP COMPLETE" --msgbox \
  509. "`cat /tmp/tmpmsg`" 7 65
  510. rm -f /tmp/tmpmsg
  511.